package test;

import java.util.ArrayList;
import java.util.List;

/**
 * @功能
 * @创建时间 2019/12/16
 */
public class erfenfa {
    public static void main(String[] args) {

//        int[] arr = new int[] { 12, 23, 34, 45, 56, 67, 77, 89, 90 };
//        System.out.println(search(arr, 12));
//        System.out.println(search(arr, 45));
//        System.out.println(search(arr, 67));
//        System.out.println(search(arr, 89));
//        System.out.println(search(arr, 99));
        List<String> list = new ArrayList();
        wweqw(list,new StringBuffer(),0,0,3);
        System.err.println(list);
    }
    public static void wweqw(List<String> list, StringBuffer cur, int left, int right, int n){
        if (n == 0){
            return;
        }
        if (n == 1){
            list.add("()");
            return;
        }
        if (left<n){

            cur.append("(");
            wweqw(list,cur,left+1,right,n);
  //          cur.deleteCharAt(cur.length() - 1);
        }
        if (right < left){

            cur.append(")");
            wweqw(list,cur,left,right + 1,n);
 //           cur.deleteCharAt(cur.length() - 1);
        }
        if (right == n){
            list.add(cur.toString());
        }
    }
    public static int search(int[] arr, int key) {
        int start = 0;
        int end = arr.length - 1;
        while (start <= end) {
            int middle = (start + end) / 2;
            if (key < arr[middle]) {
                end = middle - 1;
            } else if (key > arr[middle]) {
                start = middle + 1;
            } else {
                return middle;
            }
        }
        return -1;
    }
}
